#include"PrimitiveDrawer.h"

/////////////////
//include
/////////////////
#include"ContentManager.h"
#include"CppHeader.h"
/////////////////
//prottype
/////////////////

/////////////////
//const
/////////////////


PrimitiveDrawer::PrimitiveDrawer()
{

}
PrimitiveDrawer::~PrimitiveDrawer()
{

}
void PrimitiveDrawer::CreateBuffer(Device* device)
{
	
	line_model		= new LineModel(Vector3D(),Vector3D());
	box				= ContentManager::LoadModel("Resource/","CollisionBox.pmd");
	sphere			= ContentManager::LoadModel("Resource/","CollisionSphere.pmd");
	cylinder		= ContentManager::LoadModel("Resource/","CollisionCylinder.pmd");
	box->CreateBuffer(device);
	sphere->CreateBuffer(device);
	line_model->CreateBuffer(device);
	Vector3D tmp_vecs[3] = {};
	vertex_buffer = device->CreateVertexBuffer(tmp_vecs,3,sizeof(Vector3D));
	D3D11_INPUT_ELEMENT_DESC input_element[1]  = 
	{ 
		Layout::Get()->GetElement("POSITION")
	};
	tri_shader = ContentManager::LoadShader("a.fx","WireVS2D","WirePS2D",input_element, 1);
	tri_shader = ContentManager::LoadShader("a.fx","TriVS","TriPS",input_element,1);
	Matrix tmp_matrix = Matrix();
	world_buffer = device->CreateConstantBuffer(&tmp_matrix,sizeof(Matrix));
}
void PrimitiveDrawer::CreateShader(Device* device)
{
	/*box_model->		CreateShader(device);
	sphere_model->	CreateShader(device);
	line_model->CreateShader(device);
	D3D11_INPUT_ELEMENT_DESC input_element[1] = 
	{
		Layout::Get()->GetElement("POSITION"),
	};
	wire_frame_shader	= ContentManager::LoadShader("a.fx","WireVS","WirePS",input_element,1);
	D3D11_INPUT_ELEMENT_DESC input_element2[5] = 
	{
		Layout::Get()->GetElement("POSITION"),
		Layout::Get()->GetElement("NORMAL"),
		Layout::Get()->GetElement("UV"),
		Layout::Get()->GetElement("BONE_NUM"),
		Layout::Get()->GetElement("BONE_WEIGHT"),
	};
	normal_shader		= ContentManager::LoadShader("a.fx","PmdVS","PmdPS",input_element2,5);
	CollisionModelMaterial mat = CollisionModelMaterial();
	mat.diffuse = Vector3D(0.0f,0.0f,1.0f);
	mat.alpha = 0.1f;
	material = device->CreateConstantBuffer(&mat,sizeof(CollisionModelMaterial));*/
	box->CreateShader(device); 
	sphere->CreateShader(device);
	line_model->CreateShader(device);
}
void PrimitiveDrawer::DrawBox(DeviceContext* device_context, Vector3D pos,Vector3D size,bool is_wire_frame)
{
	box->SetPos(pos);
	box->SetScale(size);
	box->Draw(device_context);
}
void PrimitiveDrawer::DrawSphere(DeviceContext* device_context, Vector3D pos,float r)
{
	sphere->SetPos(pos);
	sphere->SetScale(r);
	sphere->Draw(device_context);
}
void PrimitiveDrawer::DrawLine(DeviceContext* device_context, Vector3D start,Vector3D end)
{
	line_model->start	= start;
	line_model->end		= end;
	line_model->Draw(device_context);
}
void PrimitiveDrawer::DrawCylinder(DeviceContext* device_context,Vector3D pos,float height,float r)
{
	cylinder->SetPos(pos);
	cylinder->SetScale(Vector3D(r,height,r));
	cylinder->Draw(device_context);
}
void PrimitiveDrawer::DrawTriangle(DeviceContext* device_context,Vector3D offset_pos, Vector3D pos1,Vector3D pos2,Vector3D pos3)
{
	Vector3D pos[3] = {pos1 + offset_pos,pos2 + offset_pos,pos3 + offset_pos};
	tri_shader->Set(device_context);
	device_context->UpdateBuffer(vertex_buffer,pos,sizeof(Vector3D)*3);
	device_context->SetVertexBuffer(vertex_buffer,sizeof(Vector3D),0);
	device_context->SetConstantBuffer(world_buffer,2);
	device_context->Draw(3,0);
}
Model*		PrimitiveDrawer::box;
LineModel*		PrimitiveDrawer::line_model;
Model*	PrimitiveDrawer::sphere;
Model*	PrimitiveDrawer::cylinder;
Shader* PrimitiveDrawer::wire_frame_shader;
Shader* PrimitiveDrawer::normal_shader;
ID3D11Buffer* PrimitiveDrawer::material;
ID3D11Buffer*	PrimitiveDrawer::vertex_buffer;
Shader*			PrimitiveDrawer::tri_shader;
ID3D11Buffer*	PrimitiveDrawer::world_buffer;